package cn.com.app.v310;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class RandomClerk {

	public static void main(String[] args) {
/*		LinkedList<Integer> ll=new LinkedList<Integer>();
        for(int i=1;i<5;i++){
            ll.add(i);
        }
        int i=0;
        while(ll.size()>0){
            i=(int)(ll.size()*Math.random());
            System.out.println(ll.get(i));
            ll.remove(i);
        }*/
		
	/*	
		int members = 11;
		int clerks = 15;
		
		int rs1 = (int)(members/clerks);
		System.out.println(rs1);
		
		int rs2 = members%clerks;
		System.out.println(rs2);
		*/
		
		List<Long> ids = new ArrayList<Long>();
		ids.add(1L);ids.add(2L);ids.add(3L);ids.add(4L);
		
		System.out.println(ids.toString().replace("[", "").replace("]", ""));
		
	/*	
		List<String> users = new ArrayList<String>();
		List<Long> tasks = new ArrayList<Long>();
		users.add("a");users.add("b");users.add("c");
		tasks.add(10L);tasks.add(20L);tasks.add(30L);tasks.add(40L);tasks.add(50L);
		
		RandomClerk r = new RandomClerk();
		Map<String,List<Long>> allot = r.allotOfAverage(users, tasks);
		
		System.out.println(allot);
		
		
	   Iterator it = allot.entrySet().iterator();
	   while (it.hasNext()) {
		    Map.Entry entry = (Map.Entry) it.next();
		    Object key = entry.getKey();
		    Object value = entry.getValue();
		    System.out.println("key=" + key + " value=" + value);
	   }*/
		
	}

	/* 
     * 平均分配 
     */  
    public Map<String,List<Long>> allotOfAverage(List<String> users, List<Long> tasks){  
        Map<String, List<Long>> allot = new ConcurrentHashMap<String, List<Long>>(); 		//保存分配的信息  
        
        if(users!=null && users.size()>0 && tasks!=null && tasks.size()>0){  
            for(int i=0; i<tasks.size(); i++){  
                int j=i%users.size();  
                if(allot.containsKey(users.get(j))){  
                    List<Long> list=allot.get(users.get(j));  
                    list.add(tasks.get(i));  
                    allot.put(users.get(j), list);  
                }else{  
                    List<Long> list=new ArrayList<Long>();  
                    list.add(tasks.get(i));  
                    allot.put(users.get(j), list);  
                }  
            }  
        }  
        return allot;  
    }  
}
